/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2011 www.pretty-tools.com
 */

var wwwPrettyTools_NravitsyaMailRuButtonConfiguration = {
    BRANCH: "extensions.prettytools.button.nravitsyamailru.",
    INSTALLED_PARAM: "installed",
    POPUP_PARAM: "popup"
};

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.getBranch = function ()
{
    return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).QueryInterface(Components.interfaces.nsIPrefBranch).getBranch(this.BRANCH);
}

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.isFirstStart = function ()
{
    try
    {
        var branch = this.getBranch();
        if (branch.prefHasUserValue(this.INSTALLED_PARAM))
            return false;

        branch.setBoolPref(this.INSTALLED_PARAM, true);
        return true;
    }
    catch(e)
    {
        dump("Exception during isFirstStart: " + ex + "\n");
        return false;
    }
}

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.isOpenInPopup = function ()
{
    try
    {
        var branch = this.getBranch();

        if (!branch.prefHasUserValue(this.POPUP_PARAM))
            return false;// Open in new tab by default

        return branch.getBoolPref(this.POPUP_PARAM);
    }
    catch(e)
    {
        dump("Exception during isOpenInPopup: " + ex + "\n");
        return false;
    }
}

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.setOpenInPopup = function (bOpenInPopup)
{
    try
    {
        this.getBranch().setBoolPref(this.POPUP_PARAM, bOpenInPopup);
    }
    catch(e)
    {
        dump("Exception during setOpenInPopup: " + ex + "\n");
    }
}

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.onOptionsPageLoad = function ()
{
    try
    {
        document.getElementById("openIn").selectedIndex = this.isOpenInPopup() ? 1 : 0;
    }
    catch(e)
    {
        dump("Exception during onOptionsPageLoad: " + ex + "\n");
    }
}

wwwPrettyTools_NravitsyaMailRuButtonConfiguration.onOptionsOK = function ()
{
    try
    {
        this.setOpenInPopup(document.getElementById("popup").selected);
    }
    catch(e)
    {
        dump("Exception during onOptionsOK: " + ex + "\n");
    }
}
